package NW_Random;

import java.util.List;
import java.util.Random;
import NWPackage.Cell;
import NWPackage.PairPreferdCandidateCell;
import NWPackage.PairPreferdCandidateMatrix;
import NWPackage.ProbabilitiesMatrix;
import NWPackage.Protocol;
import NWPackage.QueryFinderAlg;

public class MyRandom implements QueryFinderAlg{
	
	private Random rand;

	public MyRandom(int seed) {
		rand = new Random(seed);
	}
	
	public MyRandom() {
		rand = new Random();
	}
	
	@Override
	public Cell FindNextQuery(ProbabilitiesMatrix probMatrix, PairPreferdCandidateMatrix pairsPreferredMatrix, List<String> optionalWinners, Protocol protocol) {
		
		int pickIndex = -1;
		PairPreferdCandidateCell cellQ;
		int limit = pairsPreferredMatrix.getLength();
		String s = " ";
		boolean flag=false;
		do{
			pickIndex = rand.nextInt(limit);
			cellQ = pairsPreferredMatrix.getCell(pickIndex);
			if (cellQ.getPrefered_C() == null )  //if we didn't ask it already
                flag = true;
			s = cellQ.getPrefered_C();
		}
		while ((!flag ) || !(cellQ.isExistIn(optionalWinners)));
			
		return pairsPreferredMatrix.getCell(pickIndex);
	}

}
